/***************************************************************************************
Firm-embedded productivity and cross-country income differences
Alviarez, Cravino and Ramondo
Journal of Political Economy (2022)

Program: figure_A2_sales_emp_va.do
Date: October 2022

Description: Reproduces Figure A.2: Country effects: Alternative dependent variables.

*****************************************************************************************/

*-------------------------------------------------------------------------------
global typeden=1
include "set_directories.do"
set memory 64g
global lf "LF"

*Log
cap log close
log using "${clogs}/figure_A2_sales_emp_va.log",replace
*-------------------------------------------------------------------------------



*Assuming the technology transfer costs have an origin-specific component
*-----------------------------------------------------------------
clear all
use year isocode type D_A* using "${data}/estimates_agg_naics_sales_s1_base_woparent.dta", clear
rename D_A D_A_sales
rename D_A_se D_A_sales_se
merge 1:1 year isocode type using "${data}/estimates_agg_naics_emp_s1_base_woparent_salesempva.dta", keepusing(D_A*)
rename D_A D_A_emp
rename D_A_se D_A_emp_se
drop _merge
merge 1:1 year isocode type using "${data}/estimates_agg_naics_va_s1_base_woparent_salesempva.dta", keepusing(D_A*)
rename D_A D_A_va
rename D_A_se D_A_va_se
drop _merge


*Figure A2
*-----------------------------------------------------------------
foreach xx in D_A_sales D_A_emp D_A_va {
gen u_`xx' = `xx' + 1.96 * `xx'_se
gen l_`xx' = `xx' - 1.96 * `xx'_se 
}
keep year isocode type *D_A* 
gsort D_A_sales
drop year

gen t=_n
sum t

forvalues ii=1(1)`r(max)' {
local ctry`ii' = isocode[`ii']
local obs`ii' = `ii'
display "`ctry`ii'' ; `obs`ii''"
}
*

twoway rcap u_D_A_sales l_D_A_sales t, lc(red) /// 
||     rcap u_D_A_emp l_D_A_emp t, lc(blue) ///
||     rcap u_D_A_va l_D_A_va t, lc(green) /// 
||     scatter D_A_sales t, mc(red)  /// 
||     scatter D_A_emp t, mc(blue)  ///
||     scatter D_A_va t, mc(green)  ///
yline(0) yline(0) ylab(-2(1)4) xlab(1(1)25)  legend(order(4 "sales" 5 "employment" 6 "value added") rows(1) size(medlarge) bplace(n) ring(0) region(lwidth(none)))  xlabel(, valuelabel) xlabel(, angle(45)) ytitle("") xtitle("") graphregion(fcolor(white) lcolor(white)) xlabel(`obs1' "`ctry1'" `obs2' "`ctry2'"  `obs3' "`ctry3'" `obs4' "`ctry4'" `obs5' "`ctry5'" `obs6' "`ctry6'" `obs7' "`ctry7'" `obs8' "`ctry8'" `obs9' "`ctry9'" `obs10' "`ctry10'" `obs11' "`ctry11'" `obs12' "`ctry12'" `obs13' "`ctry13'" `obs14' "`ctry14'" `obs15' "`ctry15'" `obs16' "`ctry16'" `obs17' "`ctry17'" `obs18' "`ctry18'" `obs19' "`ctry19'" `obs20' "`ctry20'"  `obs21' "`ctry21'" `obs22' "`ctry22'" `obs23' "`ctry23'" `obs24' "`ctry24'" `obs25' "`ctry25'" `obs26' "`ctry26'" `obs27' "`ctry27'", labsize(small)) 

graph export "${rappendix}/fig_A2_sales_emp_va.pdf", replace

	
log close 
	
	
	